package com.wn.class30.service.impl;

import com.wn.class30.entity.Vip;
import com.wn.class30.entity.VipExample;
import com.wn.class30.mapper.VipDao;
import com.wn.class30.service.BackVipService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
@Service
public class BackVipServiceImpl implements BackVipService {
    @Resource
    private VipDao vipDao;
    @Override
    public void insertVip(Vip vip) throws Exception {
        vipDao.insertSelective(vip);
    }

    @Override
    public void updateVip(Vip vip) throws Exception {
        vipDao.updateByPrimaryKeySelective(vip);
    }

    @Override
    public void deleteById(Integer lvId) throws Exception {
        vipDao.deleteByPrimaryKey(lvId);
    }

    @Override
    public Object select(HashMap map) throws Exception {
        VipExample ex = new VipExample();
        Integer page = 0;
        if (!"".equals((String) map.get("page")) && (String) map.get("page") != null) {
            page = Integer.parseInt((String) map.get("page"));
        }
        Integer limit = 0;
        if (!"".equals((String) map.get("limit")) && (String) map.get("limit") != null) {
            limit = Integer.parseInt((String) map.get("limit"));
        }
        ex.setOffset(((long) (page - 1)) * limit);
        ex.setLimit(limit);
        return vipDao.selectByExample(ex);
    }

    @Override
    public int selectCount(HashMap map) throws Exception {
        return (int) vipDao.countByExample(null);
    }
}
